package cn.appsys.service.impl;

import cn.appsys.dao.appCategorydDao.AppCategoryMapper;
import cn.appsys.pojo.AppCategory;
import cn.appsys.service.AppCategoryService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("AppCategoryService")
public class AppCategoryServiceImpl implements AppCategoryService {

    private static final Logger LOGGER = Logger.getLogger(AppCategoryServiceImpl.class);

    @Resource
    private AppCategoryMapper appCategoryMapper;

    @Override
    public List<AppCategory> getAppCategoryById(Integer pid){
        List<AppCategory> appCategories = new ArrayList<>();
        try {
            appCategories = appCategoryMapper.qryAppCategoryById(pid);
            if(null == appCategories){
                LOGGER.error("AppCategoryServiceImpl.getAppCategoryById 方法查询为空》》》");
            }else{
                LOGGER.error("AppCategoryServiceImpl.getAppCategoryById 方法查询成功》》》");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AppCategoryServiceImpl.getAppCategoryById 方法查询异常》》》"+e.getMessage());
        }
        return appCategories;
    }

    @Override
    public AppCategory qryCategoryById(Integer id) {
        AppCategory appCategory = null;
        try {
            appCategory = appCategoryMapper.qryCategoryById(id);
            if(null == appCategory){
                LOGGER.error("AppCategoryServiceImpl.qryCategoryById 方法查询为空》》》");
                appCategory = new AppCategory();
            }else{
                LOGGER.error("AppCategoryServiceImpl.qryCategoryById 方法查询成功》》》");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AppCategoryServiceImpl.qryCategoryById 方法查询异常》》》"+e.getMessage());
            appCategory = new AppCategory();
        }
        return appCategory;
    }

    @Override
    public List<AppCategory> getAppCategoryListByParentId(Integer parentId) throws Exception {
        return appCategoryMapper.getAppCategoryListByParentId(parentId);
    }
}
